<script type="text/javascript" src="/nav/static/public/js/jquery.js"></script>
{js href="/nav/static/admin/layer/layer.js" /}
<link rel="stylesheet" type="text/css" href="http://cache.amap.com/lbs/static/main1119.css"/>
<script src="http://cache.amap.com/lbs/static/es5.min.js"></script>
<script src="http://webapi.amap.com/maps?v=1.3&key=baf1a971f3daf5c0d0095ef48ccb6479"></script>
<div id="container"></div>
<style>
    .line{
        margin: 10px;
    }
    .amap-marker-label {
        font-size: 13px;
        border: 1px solid orange;
        background: #fff;
        border-radius: 10px 0 0 0;
        color: #690441;
    }
</style>
<script>
    layer.config({
        extend: 'extend/layer.ext.js'
    });

    var map = null;
    var infoWindow = null;

    //标记
    function addMarker(lng,lat,type,content,title) {
        if(type){
            icon = '/nav/marker.png';
        }else{
            icon = '/express.png';
        }
        marker = new AMap.Marker({
            icon: icon,
            label: {
                content: title,
                offset: new AMap.Pixel(27, 25)
            },
            position: [lng,lat]
        });
        marker.setMap(map);

        infoWindow = new AMap.InfoWindow({
            offset: new AMap.Pixel(0, -20),
            content: content  //使用默认信息窗体框样式，显示信息内容
        });

        marker.content = content;
        marker.on('click', markerClick);
        marker.emit('click', {target: marker});

    }

    function markerClick(e) {
        infoWindow.setContent(e.target.content);
        infoWindow.open(map, e.target.getPosition());
    }

    map = new AMap.Map('container', {
        resizeEnable: true,
        center: ['{$center.lng}','{$center.lat}'],
        zoom: 16
    });
    addMarker('{$center.lng}','{$center.lat}',true,'订单位置');

    var express_string = '{$express_str}';
    var express_array = express_string.split('&');

    for(var i in express_array){
        addMarker(express_array[i].split(',')[0],express_array[i].split(',')[1],false,'<div><div class="line">'+express_array[i].split(',')[2]+'</div> <div class="line">当前订单量：'+express_array[i].split(',')[3]+'</div> <!--<div style="background: red;width: 5px;height: 5px;border-radius: 50%;float: right"></div>--> </div> <div class="line"> <button onclick=give_you("'+express_array[i].split(',')[4]+'")>派给他</button> </div>',express_array[i].split(',')[2]);
    }

    function give_you(id){
        var order_id = '{$order_id}';
        if(!confirm('确定要将订单分配给此配送员吗？')){
            return;
        }
        $.post('__URL__/dispatch',{order_id:order_id,'uid':id},function (json) {
            layer.msg(json.msg);
            setTimeout(function () {
                if(json.state == 1){
                    location.reload();
                }
            },700)
        })
    }

</script>